/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package CRM;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Logger;
import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Burhan
 */
public class SaveContactServlet extends HttpServlet{

    private static final Logger log = Logger.getLogger(SaveContactServlet.class.getName());

    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp)
                throws IOException {

        String firstName = req.getParameter("firstName");
        String lastName = req.getParameter("lastName");
        Company company = null;
        String email = req.getParameter("email");
        String officePhone = req.getParameter("officePhone");
        String mobilePhone = req.getParameter("mobilePhone");
        String otherPhone = req.getParameter("otherPhone");
        String fax = req.getParameter("fax");
        Date birthDate = new Date();
        String address = req.getParameter("address");
        String department = req.getParameter("department");
        ArrayList<Note> notes = new ArrayList();
        ArrayList<Task> tasks = new ArrayList();

        Contact contact = new Contact(firstName, lastName, company, email, officePhone, mobilePhone, otherPhone, fax, birthDate, address, department, notes, tasks);

        PersistenceManager pm = PMF.get().getPersistenceManager();
        try {
            pm.makePersistent(contact);
        } finally {
            pm.close();
        }

        resp.sendRedirect("/index.jsp");


        
    }

}
